{% extends "../base.html" %}

{% block body %}
  <form action='{{ request.path }}' method='POST'>
    <div>
      <input class="entry-title form-control" id="title" name="title" type="text" 
          value="{{ entry['title'] if entry else '' }}" placeholder="标题" required/>
      <br/>
      <textarea class="form-control" id="text" name="text" rows="20" cols="80">{{ entry['text'] if entry else "" }}</textarea>
      <br/>
      {% if entry %}
        <input type="hidden" name="_id" value="{{ entry['_id'] }}"/>
      {% end %}
      {% module xsrf_form_html() %}
    </div>
  </form>
  <div>
    <span id="notify"></span><br/>
    <button class="btn btn-primary" type="submit">{{ '保存' if entry else '发布' }}</button>
    &nbsp;
    <a href="{{ '/entry/show/%s' % entry['_id'] if entry else '/' }}" class="btn btn-danger">取消</a>
    {% if entry %}
      &nbsp;
      <a href="{{ '/entry/delete/%s' % entry['_id'] }}"></a>
    {% end %}
  </div>
{% end %}

{% block bottom%}
  <script type="text/javascript">
    $("button").click(function () {
      if ($("#text").val() == "") {
        $("#notify").html('<div class="alert alert-warning">'
                          + '<button class="close" data-dismiss="alert">&times;</button>'
                          + '正文内容不能为空！'
                          + '</div>');
        return null;
      } else {
        $("form").submit();
      }
    });
  </script>
{% end %}
